package cn.com.zetatech.loader.common.ftp;

import cn.com.zetatech.loader.api.exception.LoaderException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public abstract class ConnectionClient {

    String serverIP;
    int serverPort;
    String userName;
    String password;

    public abstract void login(int timeout) throws Exception;

    public abstract void pendingReset();

    public abstract InputStream get(String filePath) throws Exception;

    public abstract boolean remove(String filePath) throws Exception;

    public abstract boolean move(String sourcePath, String targetDir, String fileName) throws Exception;

    public abstract boolean copy(String sourcePath, String targetDir, String fileName) throws Exception;

    public abstract Map<String,Long> listFileSize(String dir, List<String> fileNames);

    public abstract void disconnect();

    public abstract boolean isConnected();


    public static ConnectionClient getClient(String serverIP, int serverPort, String userName, String password, String type) throws Exception {
        switch (type) {
            case "FTP":
                return new FtpClient(serverIP, serverPort, userName, password);
            case "SFTP":
                return new SftpClient(serverIP, serverPort, userName, password);
            default:
                throw new LoaderException("FTP的类型不支持，请在SFTP/FTP中选择");
        }
    }

}
